package org.paradise.dms.services.impl;

import java.util.List;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.log4j.Logger;
import org.paradise.dms.dao.impl.ApartmentDAOImpl;
import org.paradise.dms.pojo.Apartment;
import org.paradise.dms.services.ApartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.DaoException;

@Service
public class ApartmentServiceImpl implements ApartmentService {
	private static Logger log = Logger.getLogger(ApartmentServiceImpl.class);
	@Autowired
	private ApartmentDAOImpl apartmentDAOImpl;

	public ApartmentDAOImpl getApartmentDAOImpl() {
		return apartmentDAOImpl;
	}

	public void setApartmentDAOImpl(ApartmentDAOImpl apartmentDAOImpl) {
		this.apartmentDAOImpl = apartmentDAOImpl;
	}

	public String deleteApartmentByApartmentID(String apartmentid) {
		return apartmentDAOImpl.deleteApartmentbyApartmentID(apartmentid);
	}

	/**
	 * 查询出所有公寓
	 */
	public List<Apartment> listAllApartment() {

		return apartmentDAOImpl.listAllApartment();
	}

	public String updateApartment(Apartment apartment) {
		try {
			apartmentDAOImpl.update(apartment);
			log.info("DMS_info:更新公寓" + ReflectionToStringBuilder.toString(apartment).toString() + "成功！");
			return "更新公寓信息成功！";
		} catch (DaoException e) {
			log.info("DMS_error:更新公寓" + ReflectionToStringBuilder.toString(apartment).toString() + "失败！");
			log.info("失败原因" + e);
		}
		return "更新公寓信息失败！";
	}

	/**
	 * 通过ID查找某个公寓
	 * 
	 * @throws DaoException
	 */
	/*
	public List<Apartment> findApartmentByID(String apartmentid) throws DaoException {
		return apartmentDAOImpl.findApartmentByID(apartmentid);
	}
	*/
	/**
	 * 
	 */
	@SuppressWarnings("unchecked")
	public List getTotalRoomsAndAvailRoomsByApartmentID(String[] apartmentid) {
		return apartmentDAOImpl.findTotalRoomsAndAvailRoomsByApartmentID(apartmentid);
	}

	@SuppressWarnings("unchecked")
	public List getAllApartInfo() {
		return apartmentDAOImpl.findAllApartInfo();
	}

	public int getAllApartmentRows() {
		return apartmentDAOImpl.getAllApartmentRows();
	}

	public List<Apartment> listAllApartmentByPage(int pageSize, int startRow) {
		return apartmentDAOImpl.listAllApartmentByPage(pageSize, startRow);
	}
}
